﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using webapi.Entity;
using System.Data;

namespace webapi.Models
{
  public class SettingService
  {
    internal static DataRowCollection getSetting()
    {
      string sql = "select * from setting";
      return DB.ExecuteSelectSql(sql).Tables[0].Rows;
    }

    internal static DataRowCollection getSettingByGrade(string grade)
    {
      string sql = "select * from setting where grade = '" + grade + "'";
      return DB.ExecuteSelectSql(sql).Tables[0].Rows;
    }

    internal static int updateSetting(Setting setting)
    {
      string sql = string.Format("update setting set grade='{0}, begin='{1}', after='{2}', date='{3}' where id={5}", setting.grade, setting.begin, setting.after, setting.date, setting.id);
      return DB.ExecuteSql(sql);
    }

    internal static int addSetting(Setting setting)
    {
      string sql = string.Format("insert into setting(grade, begin, after, date) values('{0}', '{1}', '{2}', '{3}')", setting.grade, setting.begin, setting.after, setting.date);
      return DB.ExecuteSql(sql);
    }

    internal static int deleteSetting(int id)
    {
      string sql = "delete from setting where id =" + id;
      return DB.ExecuteSql(sql);
    }
  }
}